import Utils from "./index";
import { baseNums } from "./constants";
import { observable } from "mobx";

export class Grid {
	public rowIdx: number;
	public colIdx: number;
	public _num: number | null = null;
	@observable public showNum: number | null = null;
	public belongToPalace: number;
	public availabelNums: number[] = [];
	public availabelIdx: number = 0;
	public type: string;
	@observable public status: {
		isInit: boolean;
		isChoosed: boolean;
	} = {
		isInit: true,
		isChoosed: false,
	};

	constructor(type: string, rowIdx: number, colIdx: number) {
		this.rowIdx = rowIdx;
		this.colIdx = colIdx;
		this.belongToPalace = Utils.getPalaceKey(type, rowIdx, colIdx);
		this.type = type;
	}

	public get num(): number | null {
		return this._num;
	}

	public set num(num: number | null) {
		this.showNum = num;
		this._num = num;
	}

	public next() {
		this.availabelIdx += 1;
		return this.availabelNums[this.availabelIdx];
	}
}
